package com.woniu.microworkorderserver.businessmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microcommonsserver.entity.InspectPointInfoEntity;
import com.woniu.microcommonsserver.entity.PollingPlanInfoEntity;
import com.woniu.microcommonsserver.param.PageRequest;
import com.woniu.microworkorderserver.businessmag.mapper.InspectPlanMapper;
import com.woniu.microworkorderserver.businessmag.mapper.InspectPointMapper;
import com.woniu.microworkorderserver.businessmag.service.InspectPlanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class InspectPlanServiceImpl implements InspectPlanService {

    @Resource
    private InspectPlanMapper inspectPlanMapper;
    @Resource
    private InspectPointMapper inspectPointMapper;

    @Override
    public Long save(PollingPlanInfoEntity planInfoEntity, InspectPointInfoEntity entity) {
        inspectPlanMapper.save(planInfoEntity);
        entity.setFkPollingPlanId(planInfoEntity.getId());
        inspectPointMapper.save(entity);
        System.out.println("新增成功");
        return null;
    }

    @Override
    public PageInfo<PollingPlanInfoEntity> findPage(PageRequest request, PollingPlanInfoEntity entity) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(() -> inspectPlanMapper.findPage(request,entity));
    }

    @Override
    public void delete(long inspectPlanId) {
        inspectPlanMapper.delete(inspectPlanId);
        inspectPointMapper.delete(inspectPlanId);
    }
}
